The Return keyword
If you want to return more than one value from
a procedure or function,
you can do so using the Return
keyword. This works the same way in
WimpBasic as in BASIC.
For example
If you have a procedure
DefProcPointless(a%,b%)
a%=a%+6
b%=b%-30
EndProc
q%=6
z%=7
ProcPointless(q%,z%)
you will find that after the call to ProcPointless,
the values of q%
and z%
have not changed. This is because BASIC uses
'call by value'. This means that
nothing you do inside the procedure to the parameter
variables, affects the value
of the variables passed to the procedure.
Sometimes, you want to be able to have the procedure
change the variables
passed. Many languages allow this, which is normally
called 'call by reference'.
BASIC and WimpBasic will allow you to do this
as follows.
This time let's write
DefProcUseful(Return
a%,
Return b%)
a%=a%+6
b%=b%-3
EndProc
and call it by
q%=6
z%=7
ProcUseful(q%,z%)
after this call, q%
will be 12 and
z% 4
placing Return
before the parameter in the definition
of a function or procedure
means that any changes you make to that variable
in the procedure or function,
will affect the variable passed to it.
This can be very useful in avoiding the need
for global variables when you need
to return more than one value from a function/procedure.